package com.learning.rat.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.learning.rat.web.bean.Address;

@Controller
@RequestMapping("/hello")
public class HelloMvcController {
	private String INIT_URL = "hellomvc.jsp";

	

	@RequestMapping(value = "/mvc", method = RequestMethod.GET)
	public String init() {
		return INIT_URL;
	}

	@RequestMapping(value = "/path/{userId}", method = RequestMethod.GET)
	public String pathTest(@PathVariable String userId) {
		System.out.println(userId);
		return INIT_URL;
	}

	@RequestMapping("/product")
	@ResponseBody
	public String findProduct(
			@RequestParam(value = "productId", required = true) Integer id,
			@RequestParam(value = "productName", required = false) String name) {
		return "ID: " + id + ", Name: " + name;
	}

	@RequestMapping("/mvc1")
	public String init1() {
		return INIT_URL;
	}

	@RequestMapping(value = "/json", method = RequestMethod.GET)
	@ResponseBody
	public Address getAddress() {
		Address address = new Address();
		address.setId(101);
		address.setStreet("五菱街");

		return address;
	}

}
